package ${pkg};

import org.springframework.stereotype.Repository;
import com.blue.jdbc.BaseDao;
import ${modelPkg}.${clazz};
<#if impList??>
<#list impList as vo>
import ${vo};
</#list>
</#if>

/**
 * ${name}数据库访问
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 ${.now?string("yyyy年MM月dd日")}
 */
@Repository
public class ${clazz}Dao extends BaseDao<${clazz}>
{
	public ${clazz}Dao()
	{
	}
	
	@Override
	protected void query(StringBuilder sql, ${clazz} param)
	{
		if (param != null)
		{
			<#if columnList??>
			<#list columnList as vo>
			<#if vo.type == "Integer">
			<#if vo.field?ends_with("Id")>
				<#assign val="0">
			<#else>
				<#assign val="-1">
			</#if>
			if (param.${vo.getter}() != null && param.${vo.getter}() > ${val!"-1"})
				sql.append(" and a.${vo.column}=:${vo.field}");
				
			</#if>
			<#if vo.type == "String">
			<#if vo.field == "code">
			if (param.${vo.getter}() != null && !param.${vo.getter}().isEmpty())
				sql.append(" and a.${vo.column}=:${vo.field}");
				
			<#elseif vo.field == "name">
			if (param.${vo.getter}() != null && !param.${vo.getter}().isEmpty())
			{
				sql.append(" and a.${vo.column} like :${vo.field}");
				param.setName("%" + param.${vo.getter}() + "%");
			}
			
			</#if>
			</#if>
			</#list>
			</#if>
		}
		sql.append(" order by a.id desc");
	}
	
}
